package org.teststack.Api.Sl.MCcc;

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;
import org.apache.commons.codec.net.URLCodec;
import org.teststack.Api.RestClient;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import static org.teststack.Api.CookieManager.cookies;


public class XzqhApi {
    public static void main(String[] args) throws UnsupportedEncodingException {
        xzqhApi1();
    }


    public static int xzqhApi() {
        // 登录并更新cookies
        RestClient.loginAndUpdateCookies("liutao", "xQ5Vea/L3CMRNEwoBESSZGSVCnValY4kZcAYe3153B9/dXpazZRG8VLEuMhJdW1RhdZ/cqdUq/5FUdAxeKzdWOmZEj0sVlobwrqzRMgrIPsvyp03QTktVYRUAgloA924e5wLLSx8ECJ4WpUAB8zUa41GkyURFmyVtwxQ3EkLuabQ7V24L8EdzRfBHnFd8zRRd4RkncACXO88rrb4U7uR10ANvR0K4N2Kiai901pyztSuMfXP0fVRBW1lKj+kIONtFufTZoAL48++Q6VVr3r5B9tIC4kkwv0WzQxeOubbVKTNUi1JGnS2CEPPqjuXWJnUAO3u5PRxXmtH5+JN8yXygw==");


        Map<String, String> formParams = new HashMap<>();
        formParams.put("S_PROLOC_PROVINCE", "330000");
        formParams.put("S_PROLOC_CITY", "330100");
        formParams.put("S_PROLOC_DISTRICT", "330102");
        formParams.put("S_PROLOC_STREET", "330102001");
        formParams.put("S_QYLXDL", "11");
        formParams.put("S_GMLX", "0");



        Response response = RestAssured.given()


                .cookies(cookies)
                .params(formParams)
                .baseUri("http://10.1.10.141:9031")

                .post("/ywtSldj.do?method=getXzqhbs&csrftoken="); // 注意：可能需要有效的 CSRF Token

        int statusCode = Integer.parseInt(String.valueOf(response.getStatusCode()));
        Map<String, String> cookies = response.getCookies();
        System.out.println(statusCode);
        String body = response.getBody().asString();


        System.out.println("Response Body: " + body);




        return statusCode;
    }
    public static int xzqhApi1() throws UnsupportedEncodingException {
        // 登录并更新cookies
        RestClient.loginAndUpdateCookies("liutao", "xQ5Vea/L3CMRNEwoBESSZGSVCnValY4kZcAYe3153B9/dXpazZRG8VLEuMhJdW1RhdZ/cqdUq/5FUdAxeKzdWOmZEj0sVlobwrqzRMgrIPsvyp03QTktVYRUAgloA924e5wLLSx8ECJ4WpUAB8zUa41GkyURFmyVtwxQ3EkLuabQ7V24L8EdzRfBHnFd8zRRd4RkncACXO88rrb4U7uR10ANvR0K4N2Kiai901pyztSuMfXP0fVRBW1lKj+kIONtFufTZoAL48++Q6VVr3r5B9tIC4kkwv0WzQxeOubbVKTNUi1JGnS2CEPPqjuXWJnUAO3u5PRxXmtH5+JN8yXygw==");


        Map<String, String> formParams = new HashMap<>();
        String name1 = "建筑";
        URLCodec urlCodec = new URLCodec();
        String name = URLEncoder.encode(name1, "utf-8");
        formParams.put("name", name);
        formParams.put("proloc_district", "330102");
        formParams.put("proloc_street", "330102001");
        formParams.put("gmlx", "0");
        formParams.put("ghcomboid", "0");
        formParams.put("qylxdl", "11");



        Response response = RestAssured.given()


                .cookies(cookies)
                .params(formParams)
                .baseUri("http://10.1.10.141:9031")

                .post("/mcdj.do?method=getmcHyxx&csrftoken="); // 注意：可能需要有效的 CSRF Token

        int statusCode = Integer.parseInt(String.valueOf(response.getStatusCode()));
        Map<String, String> cookies = response.getCookies();
        System.out.println(statusCode);
        String body = response.getBody().asString();


        System.out.println("Response Body: " + body);




        return statusCode;
    }


}
